package com.zx.idc.backend.gui.ins;

import com.baomidou.mybatisplus.plugins.Page;
import com.zx.idc.backend.gui.common.BaseApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.ds.ins.entity.InsWorkOrder;
import com.zx.idc.ds.ins.service.IInsWorkOrderService;
import com.zx.idc.ds.ins.vo.InsWorkOrderVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 工单指令 前端控制器
 * </p>
 *
 * @author rxliuli
 * @since 2019-01-31
 */
@RestController
@RequestMapping("/api/insWorkOrder")
public class InsWorkOrderController extends BaseApi {

    @Autowired
    private IInsWorkOrderService iInsWorkOrderService;

    @GetMapping("/query-page")
    @RequiresPermissions("regulatory-directive:ins-work-order")
    public Result<Page<InsWorkOrderVo>> queryPage(Page<InsWorkOrderVo> page, InsWorkOrderVo insWorkOrderVo) {
        return success(iInsWorkOrderService.queryPage(page, insWorkOrderVo));
    }

    @PostMapping("/update")
    @RequiresPermissions("regulatory-directive:ins-work-order:edit")
    public Result<Boolean> update(@RequestBody InsWorkOrderVo insWorkOrderVo) {
        insWorkOrderVo.setUpdateTime(LocalDateTime.now());
        return build(iInsWorkOrderService.updateById(insWorkOrderVo));
    }

    @PostMapping("/add")
    @RequiresPermissions("regulatory-directive:ins-work-order:edit")
    public Result<Boolean> add(@RequestBody InsWorkOrder insWorkOrder) {
        insWorkOrder.setCreateTime(LocalDateTime.now());
        insWorkOrder.setUpdateTime(LocalDateTime.now());
        return build(iInsWorkOrderService.insert(insWorkOrder));
    }

    @PostMapping("/delete/batch")
    @RequiresPermissions("regulatory-directive:ins-work-order:edit")
    public Result<Boolean> deleteAll(@RequestBody List<String> ids) {
        return build(iInsWorkOrderService.deleteBatchIds(ids));
    }
}

